package com.wcm.web.handle;

import com.wcm.system.exception.DataPluginException;
import com.wcm.system.exception.NotFoundPluginException;
import com.wcm.system.exception.NotFoundPluginMethodException;
import com.wcm.system.utils.resultUtil;
import com.wcm.web.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionHandle {
    @ExceptionHandler
    @ResponseBody
    public Result handle(Exception e){
        e.printStackTrace();
        if(e instanceof DataPluginException){
            return resultUtil.fail();
        }else if(e instanceof NotFoundPluginException){
            return resultUtil.unknownPluginError();
        }else if(e instanceof NotFoundPluginMethodException){
            return resultUtil.unknownPluginMethodeError();
        }else{
            return resultUtil.unknownError();
        }

    }
}
